﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;
using CS.model;

namespace CS.DAL
{
    public class panduanmima
    {
        private DBHelper com = DBHelper.GetDBHelper();
        public bool UserLogin(string name, string pass) 
        {
            string sql = string.Format(@"select count(1) from Userinfo
                where UsersName='{0}' and UsersPwd='{1}'", name, pass);
            if ((Int32)com.ExecuteScalar(sql) == 1)
            {
                com.Close();
                return true;
            }
            com.Close();
            return false;
        }
        public List<shangp> GetGoods(string code)
        {
            List<shangp> list = new List<shangp>();
            string sql = "select * from GoodsInfo where GoodsCode like '%" + code + "%'";
            DbDataReader dr = com.GetReader(sql);
            while (dr.Read())
            {
                shangp goods = new shangp();
                if (dr["Company"] != DBNull.Value)
                {
                    goods.Company = Convert.ToInt32(dr["Company"]);
                }
                goods.SalePrice = Convert.ToDouble(dr["SalePrice"]);
                goods.GoodsCode = dr["GoodsCode"].ToString();
                goods.GoodsName = dr["GoodsName"].ToString();
                goods.GoodsState = Convert.ToInt32(dr["GoodsState"]);
                goods.OriginPrice = Convert.ToDouble(dr["OriginPrice"]);
                if (dr["Stock"] != DBNull.Value)
                {
                    goods.Stock = Convert.ToInt32(dr["Stock"]);
                }
                if (dr["Supplier"] != DBNull.Value)
                {
                    goods.Supplier = Convert.ToInt32(dr["Supplier"]);
                }
                goods.Unit = dr["Unit"].ToString().ToString();
                list.Add(goods);
            }
            com.Close();
            dr.Close();
            return list;
        }
    }
}
